package com.ss.SmartStock.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ss.SmartStock.pojo.dto.operate.OperateQueryRequest;
import com.ss.SmartStock.pojo.entity.Operation;
import com.ss.SmartStock.mapper.OperationRecordsMapper;
import com.ss.SmartStock.pojo.vo.OperateQueryVO;
import com.ss.SmartStock.service.OperationService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author author
 * @since 2024-06-20
 */
@Service
public class OperationServiceImpl extends ServiceImpl<OperationRecordsMapper, Operation> implements OperationService {

    @Resource
    private OperationRecordsMapper operationRecordsMapper;

    @Override
    public QueryWrapper<Operation> getQueryWrapper(OperateQueryRequest operateQueryRequest) {
        QueryWrapper<Operation> queryWrapper = new QueryWrapper<>();

        if (operateQueryRequest.getStatus() != null) {
            queryWrapper.eq("status", operateQueryRequest.getStatus()); // 精确匹配status字段
        }

        if (operateQueryRequest.getOperateTime() != null) {
            queryWrapper.ge("operation_time", operateQueryRequest.getOperateTime()); // 大于等于该时间
        }


        if (operateQueryRequest.getOperator() != null ) {
            queryWrapper.like("operator_id", operateQueryRequest.getOperator());
        }

        if (operateQueryRequest.getPDetailsId() != null ) {
            queryWrapper.like("p_details_id", operateQueryRequest.getPDetailsId());
        }

        // ... 可以添加更多查询条件

        return queryWrapper;
    }

    @Override
    public Page<OperateQueryVO> getOperateQueryVO(Page<Operation> operationPage, HttpServletRequest httpServletRequest) {
        return null;
    }

    @Override
    public int insertOperation(Operation operation) {
        return operationRecordsMapper.insertOperation(operation);
    }

    @Override
    public IPage<Operation> selectPageOperations(long current, long size) {
        // 创建分页对象
        Page<Operation> page = new Page<>(current, size);

        return this.operationRecordsMapper.selectPageOperations(page);
    }
}
